// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coupons_cc: 0,
    coupons_coupon: 0,
    to_pay_order_qty: 0,
    to_receipt_order_qty: 0,
    to_evaluate_order_qty: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  getUserInfoIndex() {
    var url = getApp().data.url + 'userexpand/getUserInfoIndex';
    var body = {};
    getApp().wxAjax(this.spliceUserInfoIndex, url, body);
  },

  spliceUserInfoIndex(res) {
    var resObj = res.data.body;
    this.setData({
      coupons_cc: resObj.coupons_cc,
      coupons_coupon: resObj.coupons_coupon,
      to_pay_order_qty: resObj.to_pay_order_qty > 99 ? '99+' : resObj.to_pay_order_qty,
      to_receipt_order_qty: resObj.to_receipt_order_qty > 99 ? '99+' : resObj.to_receipt_order_qty,
      to_evaluate_order_qty: resObj.to_evaluate_order_qty > 99 ? '99+' : resObj.to_evaluate_order_qty
    })
  },

  onShow: function () {
    var lmUrl = 'https://www.rongxwy.com/base/h5/leaveamessage/index.html?userid=' + wx.getStorageSync("userid");
      wx.setStorageSync('lmUrl', lmUrl);
    getApp().getCartNum(this);
    this.setData({
      userid: wx.getStorageSync("userid")
    })
    this.getUserInfoIndex();
  },
  //拨打电话
  contactUs: function () {
    wx.showActionSheet({
      itemList: ['商务合作 13511076302', '客服热线 010-84430780'],
      success: function (res) {
        if (res.tapIndex == 0) {
          wx.makePhoneCall({
            phoneNumber: '13511076302',
          })
        } else {
          wx.makePhoneCall({
            phoneNumber: '010-84430780',
          })
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  bottomNav(e) {
    getApp(e).bottomNav(e);
  },
  toaddressList() {
    wx.navigateTo({
      url: '../chaneadres/chaneadres'
    })
  },

  toMyOrders(e) {
    var order_status = e.currentTarget.dataset.order_status;
    wx.navigateTo({
      url: '../myOrders/myOrders?order_status=' + order_status
    })
  },

  tocoupon() {
    wx.navigateTo({
      url: '../coupon/coupon'
    })
  },
  togiftcertificate() {
    wx.navigateTo({
      url: '../giftcertificate/giftcertificate'
    })
  },
  toproductfavorites() {
    console.log("display product favorites page")
    wx.navigateTo({
      url: '../myFavorites/myFavorites'
    })
  },
  tolmmessage() {
    wx.navigateTo({
      url: '../lmmessage/lmmessage'
    })
  }
})